﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Acme.BookStore2.Migrations
{
    public partial class vehicle : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AppVehicle",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    ExtraProperties = table.Column<string>(nullable: true),
                    ConcurrencyStamp = table.Column<string>(maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorId = table.Column<Guid>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierId = table.Column<Guid>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    Number = table.Column<string>(maxLength: 128, nullable: false),
                    LicensePlateNumber = table.Column<string>(maxLength: 128, nullable: true),
                    Brand = table.Column<string>(maxLength: 128, nullable: true),
                    Logo = table.Column<string>(maxLength: 128, nullable: true),
                    TireType = table.Column<string>(maxLength: 128, nullable: true),
                    TotalFuelCost = table.Column<decimal>(nullable: false),
                    IsMaintaining = table.Column<bool>(nullable: false),
                    Remark = table.Column<string>(nullable: true),
                    TenantId = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppVehicle", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "VehicleDriveRecord",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorId = table.Column<Guid>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierId = table.Column<Guid>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    VehicleId1 = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_VehicleDriveRecord", x => x.Id);
                    table.ForeignKey(
                        name: "FK_VehicleDriveRecord_AppVehicle_VehicleId1",
                        column: x => x.VehicleId1,
                        principalTable: "AppVehicle",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "VehicleInspectionRecord",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorId = table.Column<Guid>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierId = table.Column<Guid>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    Cleanliness = table.Column<string>(nullable: true),
                    TirePressure = table.Column<string>(nullable: true),
                    RemainFuel = table.Column<string>(nullable: true),
                    EngineLight = table.Column<string>(nullable: true),
                    WindshieldFluid = table.Column<string>(nullable: true),
                    Remark = table.Column<string>(nullable: true),
                    VehicleId1 = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_VehicleInspectionRecord", x => x.Id);
                    table.ForeignKey(
                        name: "FK_VehicleInspectionRecord_AppVehicle_VehicleId1",
                        column: x => x.VehicleId1,
                        principalTable: "AppVehicle",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "VehicleMaintenanceRecord",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorId = table.Column<Guid>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierId = table.Column<Guid>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    VehicleId1 = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_VehicleMaintenanceRecord", x => x.Id);
                    table.ForeignKey(
                        name: "FK_VehicleMaintenanceRecord_AppVehicle_VehicleId1",
                        column: x => x.VehicleId1,
                        principalTable: "AppVehicle",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "VehicleRepairRecord",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorId = table.Column<Guid>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierId = table.Column<Guid>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    VehicleId1 = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_VehicleRepairRecord", x => x.Id);
                    table.ForeignKey(
                        name: "FK_VehicleRepairRecord_AppVehicle_VehicleId1",
                        column: x => x.VehicleId1,
                        principalTable: "AppVehicle",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "AttachFile",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorId = table.Column<Guid>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierId = table.Column<Guid>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    Name = table.Column<string>(nullable: true),
                    FileName = table.Column<string>(nullable: true),
                    FilePath = table.Column<string>(nullable: true),
                    FileUrl = table.Column<string>(nullable: true),
                    FileSource = table.Column<int>(nullable: false),
                    Remark = table.Column<string>(nullable: true),
                    ProviderName = table.Column<string>(nullable: true),
                    ProviderKey = table.Column<string>(nullable: true),
                    VehicleInspectionRecordId = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AttachFile", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AttachFile_VehicleInspectionRecord_VehicleInspectionRecordId",
                        column: x => x.VehicleInspectionRecordId,
                        principalTable: "VehicleInspectionRecord",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AppVehicle_Number",
                table: "AppVehicle",
                column: "Number");

            migrationBuilder.CreateIndex(
                name: "IX_AttachFile_VehicleInspectionRecordId",
                table: "AttachFile",
                column: "VehicleInspectionRecordId");

            migrationBuilder.CreateIndex(
                name: "IX_VehicleDriveRecord_VehicleId1",
                table: "VehicleDriveRecord",
                column: "VehicleId1");

            migrationBuilder.CreateIndex(
                name: "IX_VehicleInspectionRecord_VehicleId1",
                table: "VehicleInspectionRecord",
                column: "VehicleId1");

            migrationBuilder.CreateIndex(
                name: "IX_VehicleMaintenanceRecord_VehicleId1",
                table: "VehicleMaintenanceRecord",
                column: "VehicleId1");

            migrationBuilder.CreateIndex(
                name: "IX_VehicleRepairRecord_VehicleId1",
                table: "VehicleRepairRecord",
                column: "VehicleId1");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AttachFile");

            migrationBuilder.DropTable(
                name: "VehicleDriveRecord");

            migrationBuilder.DropTable(
                name: "VehicleMaintenanceRecord");

            migrationBuilder.DropTable(
                name: "VehicleRepairRecord");

            migrationBuilder.DropTable(
                name: "VehicleInspectionRecord");

            migrationBuilder.DropTable(
                name: "AppVehicle");
        }
    }
}
